import fetcher from "./Fetcher";
import {NumberIdAndName} from "../types/BasicModels";
import {GoodsItem} from "../components/GoodsWithSubGoodsSelector";


export function getMarketShoppingGuideSalaryPlan(marketId:number){
    return fetcher.get<ConfigureMarketShoppingGuideSalaryPlanResponse>(`markets/${marketId}/shoppingGuideSalaryPlan`)
}

export interface ConfigureMarketShoppingGuideSalaryPlanResponse {
    minimumSalary?: number;
    rules: ConfigureMarketShoppingGuideSalaryPlanRuleResponse[];
}

export interface ConfigureMarketShoppingGuideSalaryPlanRuleResponse {
    id: number;
    name: string;
    note?: string;
    commissionPercentage?: number;
    fixedSalary?: number;
    inMinimum: boolean;
    includedBrands:Array<NumberIdAndName>
    includedCategories:Array<NumberIdAndName>
    includedBrandTags:Array<NumberIdAndName>
    includedGoodsList:Array<GoodsItem>
}


export interface ConfigureMarketShoppingGuideSalaryPlanRequest {
    minimumSalary?: number;
    rules: ConfigureMarketShoppingGuideSalaryPlanRuleRequest[];
}

export interface ConfigureMarketShoppingGuideSalaryPlanRuleRequest {
    name: string;
    note?: string;
    commissionPercentage?: number;
    fixedSalary?: number;
    inMinimum: boolean;
    includedBrandIds: number[];
    includedCategoryIds:number[]
    includedBrandTagIds:Array<number>
    includedGoodsIds:Array<number>
}

export function configureMarketShoppingGuideSalaryPlan(marketId:number,request:ConfigureMarketShoppingGuideSalaryPlanRequest){
    return fetcher.post<ConfigureMarketShoppingGuideSalaryPlanResponse>(`markets/${marketId}/shoppingGuideSalaryPlan`,{},request)
}

export function reconfigureMarketShoppingGuideSalaryPlan(marketId:number,request:ConfigureMarketShoppingGuideSalaryPlanRequest){
    return fetcher.put<ConfigureMarketShoppingGuideSalaryPlanResponse>(`markets/${marketId}/shoppingGuideSalaryPlan`,{},request)
}

